<template>
	<view class="pageBox" :style="{paddingTop: statusBarHeight + 44 + 'px',}">
		<view class="topHead flex-between" :style="{top: statusBarHeight + 'px',}">
			<uni-icons type="back" size="24" @click="goBack"></uni-icons>
			<view class="title">
				贡献值
			</view>
			<view class="right" @click="onRight">
				兑换
			</view>
		</view>
		<view class="main">
			<view class="total">
				<view class="totalText flex-center">
					<view class="totalTextItem">
						贡献值
					</view>
					<view class="totalTextItem">
						{{ info.credit_2 }}
					</view>
				</view>

				<view class="use flex-between">
					<view class="useItem flex-center">
						<view class="useItemText">
							已使用
						</view>
						<view class="useItemText">
							{{ info.convert_ration }}
						</view>
					</view>

					<view class="useItem flex-center">
						<view class="useItemText">
							未使用
						</view>
						<view class="useItemText">
							{{ info.credit_2 }}
						</view>
					</view>
				</view>

			</view>

			<view class="listBox">
				<view class="listTitle flex-row">
					<view class="title">
						数量
					</view>
					<view class="title">
						备注
					</view>
					<view class="title">
						时间
					</view>
				</view>

				<view class="list">
					<view class="listItem flex" v-for="item in list" :key="item.id">
						<view class="item">
							{{ item.num }}
						</view>
						<view class="item">
							{{ item.remark }}
						</view>
						<view class="item">
							{{ item.createdAt }}
						</view>
					</view>
				</view>

				<uni-load-more :status="listStatus" @clickLoadMore="clickLoadMore"></uni-load-more>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: "",
				info: {},

				list: [],
				form: {
					page: 1,
					lastId: 0,
				},
				loading: false,
				finished: false,

			}
		},
		onLoad() {
			this.statusBarHeight = this.$mySysInfo().top;
		},
		onShow() {
			this.getInfo();
			this.list = [];
			this.form.page = 1;
			this.form.lastId = 0;
			this.loading = false;
			this.finished = false;
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		computed: {
			listStatus() {
				if (this.finished) return "noMore";
				if (this.loading) return "loading";
				return "more";
			}
		},
		methods: {
			onRight() {
				uni.navigateTo({
					url: '/property/exchange'
				})
			},
			goBack() {
				const pages = getCurrentPages()
				if (pages.length === 1) {
					if (typeof params === 'number') {
						history.go(-params)
					} else {
						history.back()
					}
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			},
			getInfo() {
				this.$post({
					module: "User",
					interface: "1000",
				}).then(res => {
					this.info = res;
				})
			},
			getList() {
				if (this.loading || this.finished) return;
				this.loading = true;
				this.$post({
					module: 'Finance',
					interface: 2100,
					data: {
						creditType: "credit_2",
						...this.form
					},
				}).then(res => {
					this.list = this.list.concat(res.list);
					this.form.page = res.currentPage + 1;
					this.form.lastId = res.lastId;
					if (this.form.page > res.lastPage) {
						this.finished = true;
					}
					this.loading = false;
					if (this.form.page == 2) {
						this.getList();
					}
				}).catch(() => {
					this.loading = false;
				})
			},
			clickLoadMore() {
				this.getList();
			},
		},
	}
</script>

<style scoped lang="scss">
	.pageBox {
		width: 100%;
		min-height: calc(100vh - var(--window-top));
		background-color: #ffffff;

		.topHead {
			background-color: #ffffff;
			height: 88rpx;
			width: 100%;
			padding: 0 32rpx;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 3;

			.title {
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #000000;
				position: absolute;
				top: 22rpx;
				left: 50%;
				transform: translate(-50%, 0);
			}

			.right {
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #F2615F;
			}
		}

		.main {

			.total {
				width: 100%;
				height: 354rpx;
				background-image: url("http://www.bobei.shop/static/third/topHeadBg.png");
				background-size: 100% 100%;
				background-repeat: no-repeat;
				padding-top: 76rpx;
				position: relative;

				.totalText {
					flex-direction: column;
					margin: 0 auto;

					.totalTextItem {
						font-size: 36rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: normal;
						color: #FFFFFF;
					}

					.totalTextItem:nth-last-of-type(1) {
						margin-top: 16rpx;
					}
				}

				.use {
					width: 100%;
					height: 120rpx;
					background: linear-gradient(180deg, #FF7270 0%, #F2615F 32%, #F2615F 69%, #FF7270 100%);
					position: absolute;
					bottom: 0;
					left: 0;
					z-index: 1;

					.useItem {
						width: 50%;
						flex-direction: column;

						.useItemText {
							font-size: 32rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: normal;
							color: #FFFFFF;
						}

						.useItemText:nth-last-of-type(1) {
							margin-top: 12rpx;
						}
					}
				}


			}

			.listBox {
				width: 100%;
				margin-top: 38rpx;

				.listTitle {
					padding: 0 30rpx;

					.title {
						font-size: 36rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: bold;
						color: #000000;
					}

					.title:nth-of-type(1) {
						width: 26%;
					}

					.title:nth-of-type(2) {
						width: 38%;
					}

					.title:nth-of-type(3) {
						width: 36%;
					}
				}

				.list {
					padding: 20rpx 30rpx 0;

					.listItem {
						align-items: flex-start;
						.item {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: normal;
							color: #666666;
							margin-top: 16rpx;
							word-break: break-all;

						}

						.item:nth-of-type(1) {
							width: 26%;
						}

						.item:nth-of-type(2) {
							width: 38%;
							flex-direction: column;
						}

						.item:nth-of-type(3) {
							width: 36%;
							flex-direction: column;
						}
					}
				}
			}
		}

	}
</style>
